package com.bysj.studentsystem.controller;

import com.bysj.studentsystem.vo.ResponseDataVO;
import com.bysj.studentsystem.entity.SysMenu;
import com.bysj.studentsystem.service.SysMenuService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (SysMenu)表控制层
 *
 * @author makejava
 * @since 2024-03-09 16:51:49
 */
@RestController
@RequestMapping("menu")
public class SysMenuController {
    /**
     * 服务对象
     */
    @Resource
    private SysMenuService sysMenuService;

    @GetMapping
    public ResponseDataVO queryByTree(){
        return new ResponseDataVO().ok(this.sysMenuService.queryByTree());
    }

    /**
     * 分页查询
     *
     * @param sysMenu 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
//    @GetMapping
//    public ResponseEntity<Page<SysMenu>> queryByPage(SysMenu sysMenu, PageRequest pageRequest) {
//        return ResponseEntity.ok(this.sysMenuService.queryByPage(sysMenu, pageRequest));
//    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseDataVO<SysMenu> queryById(@PathVariable("id") Integer id) {
        return new ResponseDataVO().ok(this.sysMenuService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysMenu 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<SysMenu> add(@RequestBody SysMenu sysMenu) {
        return ResponseEntity.ok(this.sysMenuService.insert(sysMenu));
    }

    /**
     * 编辑数据
     *
     * @param sysMenu 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<SysMenu> edit(@RequestBody SysMenu sysMenu) {
        return ResponseEntity.ok(this.sysMenuService.update(sysMenu));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(@RequestParam("id") Integer id) {
        return ResponseEntity.ok(this.sysMenuService.deleteById(id));
    }

}

